var spimg = document.querySelector(".xq-sj img");
var spIF = document.querySelector(".xq-r-1");
var spMONEY = document.querySelector(".b-money");

/* 将商品信息从本地数据中导入网页 */
window.onload = function () {
    var nowWare = find("now");
    spimg.src = getIFoflocal(find(nowWare), "src");
    spMONEY.innerHTML = getIFoflocal(find(nowWare), "money");
    spIF.innerHTML = getIFoflocal(find(nowWare), "text");
}
var numreduce = document.querySelectorAll(".reduce");
var numadd = document.querySelectorAll(".add");
for (i = 0; i < numadd.length; i++) {
    numreduce[i].addEventListener("click", reduce);
    numadd[i].addEventListener("click", add);
}


/* 检查商品数量，防止商品数量为数字且<=0 */
function checkWareNum(x) {
    if (x.value == 0 || x.value == "") {
        x.value = 1;
        x.parentNode.querySelector(".reduce").disabled = true;
    }
}

/* 商品数量-1 */
function reduce() {
    var partent = this.parentNode;
    var zhi = partent.querySelector(".inputNum");
    zhi.value--;
    if (zhi.value == 1) partent.querySelector(".reduce").disabled = true;
}

/* 商品数量+1 */
function add() {
    var partent = this.parentNode;
    partent.querySelector(".reduce").disabled = false;
    var zhi = partent.querySelector(".inputNum");
    zhi.value++;
}